import path from "path";
import { loadEnv } from "./build/util";

const { VITE_PORT, VITE_PUBLIC_PATH, VITE_PROXY } = loadEnv();
const pathResolve = (pathStr: string) => path.resolve(__dirname, pathStr);

module.exports = {
  base: VITE_PUBLIC_PATH,
  alias: {
    "/@/": pathResolve("./src"),
  },
  cssPreprocessOptions: {
    // 这里注意，键名是scss不是sass！一字之差能让你折腾好久
    scss: {
      // 这里写你想导入全局scss变量的路径
      // 这里注意只能写相对路径，alias貌似在css中不会生效
      additionalData: "@import './src/style/var.scss';",
    },
  },
  optimizeDeps: {
    include: ["lodash-es", "ant-design-vue/es/locale/zh_CN"],
  },
  minify: "esbuild", // 压缩
  esbuildTarget: "es2019",
  hostname: "localhost", // ip地址
  port: VITE_PORT, // 端口号
  open: false, // 是否自动在浏览器打开
  https: false, // 是否开启 https
  ssr: false, // 是否服务端渲染
  proxy: {
    // 配置代理
    "/api": {
      target: VITE_PROXY,
      changeOrigin: true,
      ws: true,
      // rewrite: (path: string) => path.replace(/^\/api/, ""),
    },
  },
};
